<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
</head>

<body>
    <pre class="aa"></pre>
    <div style="display:none" class="w">有时候，其实害怕寂寞，</div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    var index = 0;
    var word = $('.w').html();
    var wordLen = word.split('').length
    function type() {
        var newWord = word.substring(0,++index)
        $('.aa').html(newWord)
        if(index===wordLen){
            clearInterval(timer)
        }
    }
    var timer = setInterval(type, 200);
</script>

</html>